package com.lmc.form.script;

import com.fasterxml.jackson.core.type.TypeReference;
import com.free.bsf.core.util.JsonUtils;
import com.free.bsf.core.util.StringUtils;
import lombok.val;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class DataSourceScripts {
    public static class DataSourceScript{
        public String name;
        public String description;
        public boolean use=true;
        public String script;
        public String loadOrder;//page_preload,page_loading,page_loaded
        public int cacheTime;
    }

    private List<DataSourceScript> datasources = new ArrayList<>();
    public DataSourceScripts(String script){
        //script="{name:'a',description:'b',action:'add',time:'before',scripts:[{condition:'form.bbb==1||form.ccc==2',script:'form.bbb=5;'}]}";
        datasources= JsonUtils.deserialize(script,new TypeReference<List<DataSourceScripts.DataSourceScript>>(){});
    }

    public List<DataSourceScripts.DataSourceScript> filter(){
        val list = datasources.stream().filter((e)->e.use==true).collect(Collectors.toList());
        return list;
    }
}
